package com.ruis.kotboot.common.core

import com.alibaba.fastjson.JSON
import org.apache.commons.lang3.StringUtils

class RuisJsonModel(str:String?) {
    private val jsons: String? = str
    private var map: MutableMap<String, Any?>? = null

    init {
        try {
            map= JSON.parseObject(jsons,Map::class.java) as MutableMap<String, Any?>
        }catch (e:Exception){
            map= HashMap()
        }
    }

    fun get(key:String):Any?{
        return map?.get(key)
    }
    fun put(key:String,value:Any?){
        map?.put(key,value)
    }

    fun containsKey(key:String):Boolean{
        return map?.containsKey(key)?:false
    }
    fun containNotBlink(key:String):Boolean{
        try {
            if (!containsKey(key)) return false
            if (StringUtils.isNotBlank(get(key)as String))
                return true
        }catch (e:Exception){}
        return false
    }

    override fun toString(): String {
        try {
            val str=JSON.toJSONString(map)
            if (StringUtils.isNotBlank(str))
                return str
        }catch (e:Exception){}
        return jsons?:""
    }
}